package DataTags;

import java.io.File;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import junit.framework.TestCase;
/**
 * this class is junit test class  for DataTagsAdapterDB class
 * @author oz
 *
 */
public class testDataTagsAdapterDB extends TestCase {
	DataTagsToFiles myData=new DataTagsToFiles();
	DataTagsAdapterDB myDBadapter=new DataTagsAdapterDB(myData);
	public void testing(){
		File f = new File("");
        String go=new String(f.getAbsolutePath());
        System.out.println(go);
		String path=new String(go+"/logics/");//obviously on different computer the path to this file is different
		//and you need to change it.
		File fi=new File(path+"ClasifyByMdate.class");
		Date d=new Date(fi.lastModified());
		String last_m=new String(d.toGMTString());
		String []tags="logics@mDate@".split("@");
		myDBadapter.addTagsTo(fi.getName(), last_m,fi.getPath(), tags);
		Iterator<DataTagsToFiles>itTags=myDBadapter.tagsOfFile("ClasifyByMdate.class").iterator();
		while(itTags.hasNext()){
			String st=new String( itTags.next().getTag());
			if((st.equalsIgnoreCase("logics"))||(st.equalsIgnoreCase("mDate"))){
				assertTrue(true);
			}
			else{
				assertTrue(false);
			}
		}
		
		myDBadapter.deleteFile(fi);
		Iterator<files>itFiles=myDBadapter.simpleSearchAllFiles().iterator();
		boolean flag=true;
		while(itFiles.hasNext()&&(flag)){
			String st=new String(itFiles.next().getName());
			if((st.equalsIgnoreCase("ClasifyByMdate.class"))){
				flag=false;
			//	assertTrue(flag);
			}
			
		}
		
	}
}
